package com.mayikt;

/**
 * @ClassName Test003
 * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
 * @Version V1.0
 **/
public class Test003 extends Thread {
    private int count = 0;
    private Object lockObject = new Object();

    @Override
    public void run() {
        while (count < 10000) {
            create();
        }
    }

    private void create() {
        synchronized (lockObject) {
            count++;
            System.out.println(Thread.currentThread().getName() + "," + count);

        }
    }


    public static void main(String[] args) throws InterruptedException {
        Long startTime = System.currentTimeMillis();
        Test003 test003 = new Test003();
        Thread t1 = new Thread(test003);
        Thread t2 = new Thread(test003);
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        Long endTime = System.currentTimeMillis();
        System.out.println(endTime - startTime);
    }
}
